package com.zj.leetcode.medium;

/**
 * @program: algorithm
 * @description:
 * 553. 最优除法
 * @author: Zhang Bo
 * @create: 2022-01-14 14:33
 **/
public class OptimalDivision{
    public static void main(String[] args) {
        Solution solution = new OptimalDivision().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        /**
         * ......
         * 从第二个到最后一个加个括号就好了
         * @param nums
         * @return
         */
        public String optimalDivision(int[] nums) {
            if (nums.length == 1)
                return nums[0] + "";
            if (nums.length == 2)
                return nums[0] + "/" + nums[1];
            StringBuilder res = new StringBuilder(nums[0] + "/(" + nums[1]);
            for (int i = 2; i < nums.length; i++) {
                res.append("/" + nums[i]);
            }
            res.append(")");
            return res.toString();
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
